'''
ImportError: create_pandas_dataframe_agent has been moved to langchain experimental. See https://github.com/langchain-ai/langchain/discussions/11680for more information.
Please update your import statement from: `langchain.agents.create_pandas_dataframe_agent` to `langchain_experimental.agents.create_pandas_dataframe_agent`.
'''
# from langchain.agents import create_pandas_dataframe_agent
from langchain_openai.llms import OpenAI
from langchain_experimental.agents import create_pandas_dataframe_agent
import pandas as pd


def query_agent(data, query):
    # parse the csv file and create a pandas dataframe from its contents
    df = pd.read_csv(data)

    llm = OpenAI()

    # create a pandas dataframe agent
    agent = create_pandas_dataframe_agent(llm, df, verbose=True)

    # Python REPL:A Python shell used to evaluating and executing Python commands.
    # It takes python code as input and outputs the result.The input python code can be generated from another tool in the Langchain
    return agent.run(query)
